// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: Spikes Activator Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

private alias object.value0 : object.endSlot
private alias object.value1 : object.startSlot


// ========================
// Events
// ========================

event ObjectUpdate
	arrayPos0 = object.startSlot
	while arrayPos0 < object.endSlot
		object[arrayPos0].priority = PRIORITY_ACTIVE
		arrayPos0++
	loop
end event


event ObjectDraw
	arrayPos0 = object.startSlot
	while arrayPos0 < object.endSlot
		if stage.state == STAGE_RUNNING
			object[arrayPos0].priority = PRIORITY_INACTIVE
		else
			object[arrayPos0].priority = PRIORITY_ACTIVE
		end if

		arrayPos0++
	loop
end event


event ObjectStartup
	foreach (TypeName[Spikes Activator], arrayPos0, ALL_ENTITIES)
		arrayPos1 = arrayPos0
		object[arrayPos0].endSlot = object[arrayPos0].propertyValue

		temp0 = false
		while temp0 == false
			if object[arrayPos1].type == TypeName[Moving Spikes]
				object[arrayPos0].startSlot = arrayPos1
				temp0 = true
			else
				arrayPos1++
				if arrayPos1 >= 0x420
					temp0 = true
				end if
			end if
		loop

		object[arrayPos0].endSlot += object[arrayPos0].startSlot
	next
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-8, -8, 16, 16, 168, 18) // "Trigger" - #0
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "activateSlot")
end event
